import request from '@/utils/request'

// 分页查询职位列表
export function positionList(data) {
  return request({
    url: '/applet-api/osam/position/pageposition',
    method: 'post',
    data,
    ContentType: 'application/x-www-form-urlencoded',
  })
}

// 删除职务
export function deletePosition(positionId) {
  return request({
    url: `/applet-api/osam/position/delete/${positionId}`,
    method: 'post',
    ContentType: 'application/x-www-form-urlencoded',
  })
}

// 更新职务状态
export function updatePositionStatus(data) {
  return request({
    url: '/applet-api/osam/position/updatestatus',
    method: 'post',
    data
  })
}

//   创建职务
export function createPosition(data) {
  return request({
    url: '/applet-api/osam/position/create',
    method: 'post',
    data
  })
}

//   更新职务
export function updatePosition(data) {
  return request({
    url: '/applet-api/osam/position/update',
    method: 'post',
    data
  })
}

// 部门列表分页查询
export function deptList(data) {
  return request({
    url: '/applet-api/dept/list',
    method: 'post',
    data
  })
}

// 新建部门
export function createDept(data) {
  return request({
    url: '/applet-api/dept/create',
    method: 'post',
    data
  })
}

// 批量更新部门信息
export function updateDept(data) {
  return request({
    url: '/applet-api/dept/update',
    method: 'post',
    data
  })
}

// 用户列表分页查询
export function userList(data) {
  return request({
    url: '/applet-api/user/list',
    method: 'post',
    data
  })
}

// 新建用户
export function createUser(data) {
  return request({
    url: '/applet-api/user/create',
    method: 'post',
    data
  })
}

// 批量更改部门属性
export function updatePro(data) {
  return request({
    url: '/applet-api/dept/update/pro',
    method: 'post',
    data
  })
}

// 批量更改用户属性
export function updateUser(data) {
  return request({
    url: '/applet-api/user/update/pro',
    method: 'post',
    data
  })
}

// 获取父部门编号所有的子级部门
export function getParent(parentId) {
  return request({
    url: `/applet-api/dept/get/parent/${parentId}`,
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded',
  })
}

// 获得所有资源的资源树
export function resourceTree(parentId) {
  return request({
    url: '/applet-api/osam/resource/tree',
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded',
  })
}

// 获取指定职务的资源
export function positionResourceTree(positionId) {
  return request({
    url: `/applet-api/resource/tree/${positionId}`,
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded'
  })
}

// 保存指定职务的资源
export function saveResource(data) {
  return request({
    url: `/applet-api/resource/save`,
    method: 'post',
    data
  })
}

// 上传文件
export function uploadFile(param) {
  const formdata = new FormData();
  formdata.append("file", param)
  return request({
    // url: '/applet-api/ud/u/user',
    url: '/applet-api/ud/profilePhoto/u',
    method: 'post',
    ContentType: 'multipart/form-data',
    data: formdata,
  })
}

// 文件与主体绑定
export function connectUser(param) {
  return request({
    url: '/applet-api/ud/f/save',
    method: 'post',
    data: param,
  })
}


// 获取指定职务的资源
export function resourceList(positionId) {
  return request({
    url: `/applet-api/resource/list/${positionId}`,
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded'
  })
}

// 获取数据权限
export function getResource(positionId) {
  return request({
    url: `/applet-api/resource/${positionId}`,
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded'
  })
}

// 设置数据权限
export function setResource(positionId, dataRange) {
  return request({
    url: `/applet-api/resource/${positionId}/${dataRange}`,
    method: 'get',
    ContentType: 'application/x-www-form-urlencoded'
  })
}
